home *** CD-ROM | disk | FTP | other *** search
/ Business Assistant / Business Assistant.iso / checkb / nojcb / cbmain.inc < prev   
Text File  |  1989-09-09  |  29KB  |  620 lines

  1. /*----------------------------------------------------------------------------
  2.  *  File:     CBMAIN.INC  (in Turbo C 1.5)
  3.  *
  4.  *  Purpose:  Provides functions and structures for CB.
  5.  *
  6.  *  Author:   Steven "Noji" Ratzlaff
  7.  *
  8.  *  Date:     09 Sep 1989
  9.  *--------------------------------------------------------------------------*/
  10.   struct      EntryPrompt
  11.               {
  12.                 char    msg[MSG_LEN];
  13.                 char    var[LINE_LIM];
  14.               } input[] =
  15.               {
  16.                 { "Check or Item:",              0 },
  17.                 { "Date:",                       0 },
  18.                 { "Amount:",                     0 },
  19.                 { "Purpose:",                    0 },
  20.                 0
  21.               };
  22.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  23.   struct      Record                   /* record of each transaction        */
  24.               {
  25.                 int     ind;                /* index number of the record   */
  26.                 char    check[INPUT_SP];    /* check number / xaction type  */
  27.                 char    date[INPUT_SP];     /* date of transaction          */
  28.                 char    amt[INPUT_SP];      /* amount                       */
  29.                 char    pur[MSG_LEN];       /* purpose of transaction       */
  30.                 char    bal[INPUT_SP];      /* balance after transaction    */
  31.                 struct Record
  32.                         *next;              /* pointer to the next record   */
  33.               } *head,
  34.                 *tail,
  35.                 *cur;
  36.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37.   char        *func_key[] =
  38.               {
  39.                 "WordPerfect",         /*  F1  */
  40.                 "DEP",                 /*  F2  */
  41.                 "VIS",                 /*  F3  */
  42.                 "UCC",                 /*  F4  */
  43.                 "Loan Payment",        /*  F5  */
  44.                 "Food-4-Less",         /*  F6  */
  45.                 "Albertsons",          /*  F7  */
  46.                 "Dr. Myers",           /*  F8  */
  47.                 "Visa Credit Payment", /*  F9  */
  48.                 "Tithing",             /*  F10 */
  49.                 0
  50.               };
  51.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  52.   int         nmonth[] =
  53.                 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  54.   char        *month[] =
  55.                 {
  56.                   "XXX", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  57.                   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  58.                 };
  59. /*--------------------------------------------------------------------------*/
  60. main(argc, argv)                       /* CB                                */
  61.   int         argc;
  62.   char        **argv;
  63. {
  64.   struct ffblk
  65.               block;                   /* structure of file attributes      */
  66.   int         yn = 0;                  /* yes or no?                        */
  67.   char        *acct = *++argv,         /* account file name                 */
  68.               filepath[MAX_PATH];      /*    "      "  pathname             */
  69.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  70.   strcpy(filepath, CB_DIR);            /* specify the directory of the path */
  71.   if (argc == 2)
  72.   {
  73.     beg_bal[0] = last_check[0] = '\0'; /* initialize all global variables   */
  74.     for (yn = 0; yn < ELEMENTS; yn++)
  75.       input[yn].var[0] = '\0';
  76.     yn = 0;
  77.     head = tail = cur = NULL;
  78.     prompt = getenv("PROMPT");
  79.     strcat(filepath, strupr(acct));
  80.     strcat(filepath, ".CB");
  81.     if (findfirst(filepath, &block, 0) == 0)     /* if the file exists      */
  82.       transact(filepath, yn);                    /*   transact business     */
  83.     else
  84.     {
  85.       printf("  *** Account '%s' not found\n%s", acct,
  86.              "      Create a new account?  ");
  87.       while (yn != 'y' && yn != 'n')
  88.         yn = tolower(getch());
  89.       if (yn == 'y')
  90.       {
  91.         printf("\n      Enter the beginning balance:  ");
  92.         gets(beg_bal);
  93.         transact(filepath, yn);
  94.       }
  95.     }
  96.   }                                    /* end of if (argc == 2) ...         */
  97.   else
  98.   {
  99.     printf("%s\n\n", Version);
  100.     directory(FALSE);                  /* display the account directory     */
  101.   }
  102.   return 0;                            /* successful completion             */
  103. }                                      /* end of main()                     */
  104. /*----------------------------------------------------------------------------
  105.  *  before_date():  Determines whether date1 is chronologically before date2.
  106.  *            Both dates must be properly formatted beforehand.
  107.  *--------------------------------------------------------------------------*/
  108.   int
  109. before_date(date1, date2)
  110.   char        *date1,                  /* the date to test                  */
  111.               *date2;                  /* the date in question              */
  112. {
  113.   char        c_day1[INPUT_SP],        /* the day string                    */
  114.               c_day2[INPUT_SP],        /*  "   "     "                      */
  115.               c_month1[INPUT_SP],      /*  "  month  "                      */
  116.               c_month2[INPUT_SP],      /*  "    "    "                      */
  117.               c_year1[INPUT_SP],       /*  "  year   "                      */
  118.               c_year2[INPUT_SP];       /*  "    "    "                      */
  119.   long        total1,                  /* the composite of date1            */
  120.               total2;                  /*  "      "      " date2            */
  121.   int         i_day1,                  /* the day number                    */
  122.               i_day2,                  /*  "   "     "                      */
  123.               i_month1,                /*  "  month  "                      */
  124.               i_month2,                /*  "    "    "                      */
  125.               i_year1,                 /*  "  year   "                      */
  126.               i_year2,                 /*  "    "    "                      */
  127.               i;                       /* arbitrary counter                 */
  128.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  129.   strncpy(c_day1, date1, 2);           /* get the days                      */
  130.   strncpy(c_day2, date2, 2);
  131.   c_day1[2] = c_day2[2] = '\0';
  132.   i_day1 = atoi(c_day1);
  133.   i_day2 = atoi(c_day2);
  134.  
  135.   strcpy(c_month1, date1);             /* get the months                    */
  136.   strcpy(c_month2, date2);
  137.   for (i = 0; i < 3; i++)
  138.   {
  139.     c_month1[i] = c_month1[i + 3];
  140.     c_month2[i] = c_month2[i + 3];
  141.   }
  142.   c_month1[3] = c_month2[3] = '\0';
  143.   for (i = 1; i < 13; i++)
  144.   {
  145.     if (stricmp(c_month1, month[i]) == 0)
  146.       i_month1 = i;
  147.     if (stricmp(c_month2, month[i]) == 0)
  148.       i_month2 = i;
  149.   }
  150.  
  151.   strcpy(c_year1, date1);              /* get the years                     */
  152.   strcpy(c_year2, date2);
  153.   for (i = 0; i < 2; i++)
  154.   {
  155.     c_year1[i] = c_year1[i + 7];
  156.     c_year2[i] = c_year2[i + 7];
  157.   }
  158.   c_year1[2] = c_year2[2] = '\0';
  159.   i_year1 = atoi(c_year1);
  160.   i_year2 = atoi(c_year2);
  161.  
  162.   total1 = (long) i_day1 + (long) i_month1 * 100L + (long) i_year1 * 10000L;
  163.   total2 = (long) i_day2 + (long) i_month2 * 100L + (long) i_year2 * 10000L;
  164.  
  165.   return (total1 < total2);
  166. }                                      /* end of before_date()              */
  167. /*----------------------------------------------------------------------------
  168.  *  clear_line():  Clears the line from the current cursor pos to the end.
  169.  *--------------------------------------------------------------------------*/
  170.   void
  171. clear_line(xpos)
  172.   int         xpos;
  173. {
  174.   while (++xpos < 70)
  175.     printf(" ");
  176. }                                      /* end of clear_line()               */
  177. /*----------------------------------------------------------------------------
  178.  *  directory():  Displays a directory listing by account names.
  179.  *--------------------------------------------------------------------------*/
  180.   void
  181. directory(menucall)
  182.   int